var fs = require('fs');
var path = require('path');
var TChannel = require('tchannel');
var HyperbahnClient = require('tchannel/hyperbahn/');
var rootChannel = TChannel();

var hyperbahnClient = HyperbahnClient({
    tchannel: rootChannel,
    serviceName: 'keyvalue-client',
    hostPortList: ['172.30.32.88:5001', '172.30.32.88:5002'],
    hardFail: true,
    reportTracing: false,
});


var keyChan = hyperbahnClient.getClientChannel({
     serviceName: 'core_order_service'
});

// console.log(keyChan);

var keyThrift = rootChannel.TChannelAsThrift({
    entryPoint: path.join(__dirname, 'thrift/core.order.thrift'),
    channel: keyChan
});

var obj = {"orderId":111, 
"visitId":1,
"testlist":[]};

var start = async function () {
	var ret = keyThrift.request({
     // serviceName: 'core_sample_service',
     timeout: 10000,
     hasNoParent: true
		});
	// ret.send('CoreOrderServer::getOrderBeanById', null, {orderid:18567021297931265}, 
	// 	 function onResponse(err, resp) {
	// 	    if (err) {
	// 	            console.log('got error', err);
	// 	        } else {
	// 	            console.log('got response', resp);
	// 	        }
	// 	        // keyChan.close();
	// 	        // rootChannel.close();
	// 	});

	var s = await ret.send('CoreOrderServer::getOrderBeanById', null, {orderid:18567021297931265}, onResponse);
	// console.log(s);
		 function onResponse(err, resp) {
		 	// start();
		    if (err) {
		            console.log('got error', err);
		        } else {
		            console.log('got response', resp);
		        }
		        // keyChan.close();
		        // rootChannel.close();
		}
};
start();


